﻿
Imports System.Threading
Imports std

'use threadpool here
Public Class distributeOperation2
    Inherits distributeOperation

    Public Const defaultThreadCount As Int64 = 4
    Private threadpool As threadpool = Nothing

    Public Function queuelength() As Int64
        Return threadpool.queueLength()
    End Function

    'threadpool does not support to reduce thread now
    Public Property threadCount() As Int64
        Get
            Return threadpool.threadCount()
        End Get
        Set(ByVal value As Int64)
            threadpool.threadCount = value
        End Set
    End Property

    Public Sub New()
        threadpool = New threadpool()
        start()
    End Sub

    Public Sub start(Optional ByVal threadCount As Int64 = defaultThreadCount)
        threadpool.start(threadCount)
    End Sub

    Protected Overrides Sub startInfo(Of infoType As distrInfo(Of argType, returnType), argType, returnType) _
                                     (ByVal info As infoType)
        threadpool.insertJob(AddressOf distrImpl(Of infoType, argType, returnType), info)
    End Sub

    Public Sub [stop]()
        threadpool.stop()
    End Sub
End Class
